<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <!-- <el-form-item label="公司代码" prop="factoryCode">
         <el-input
           v-model="queryParams.factoryCode"
           placeholder="请输入公司代码"
           clearable
           @keyup.enter.native="handleQuery"
         />
       </el-form-item>-->
      <el-form-item label="订单号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="派工单号" prop="danhao">
        <el-input
          v-model="queryParams.danhao"
          placeholder="请输入派工单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="订单号" prop="orderNo">
         <el-input
           v-model="queryParams.orderNo"
           placeholder="请输入订单号"
           clearable
           @keyup.enter.native="handleQuery"
         />
       </el-form-item>-->
      <!--  <el-form-item label="合同号" prop="contractNo">
          <el-input
            v-model="queryParams.contractNo"
            placeholder="请输入合同号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>-->
      <el-form-item label="排产编号" prop="pcCode">
        <el-input
          v-model="queryParams.pcCode"
          placeholder="请输入排产编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="排产日期" prop="pcDate">
        <el-date-picker clearable
                        v-model="queryParams.pcDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择排产日期">
        </el-date-picker>
      </el-form-item>
     <!-- <el-form-item label="生产日期" prop="scDate">
        <el-date-picker clearable
                        v-model="queryParams.scDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择生产日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="交货日期" prop="jhDate">
        <el-date-picker clearable
                        v-model="queryParams.jhDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择交货日期">
        </el-date-picker>
      </el-form-item>-->
      <!--      <el-form-item label="生产线代码" prop="lineCode">
              <el-input
                v-model="queryParams.lineCode"
                placeholder="请输入生产线代码"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="生产线名称" prop="lineName">
              <el-input
                v-model="queryParams.lineName"
                placeholder="请输入生产线名称"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>-->
      <el-form-item label="工位代码" prop="gwCode">
        <el-input
          v-model="queryParams.gwCode"
          placeholder="请输入工位代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工位名称" prop="gwName">
        <el-input
          v-model="queryParams.gwName"
          placeholder="请输入工位名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     <!-- <el-form-item label="员工工号" prop="empNum">
        <el-input
          v-model="queryParams.empNum"
          placeholder="请输入员工工号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="员工姓名" prop="empName">
        <el-input
          v-model="queryParams.empName"
          placeholder="请输入员工姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="领料物料" prop="dyYclCode">
        <el-input
          v-model="queryParams.dyYclCode"
          placeholder="请输入领料物料"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报工物料" prop="dyProCode">
        <el-input
          v-model="queryParams.dyProCode"
          placeholder="请输入报工物料"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料识别码" prop="itemIdentifyCode">
        <el-input
          v-model="queryParams.itemIdentifyCode"
          placeholder="请输入物料识别码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--     <el-form-item label="工序产品编号" prop="gxProCode">
             <el-input
               v-model="queryParams.gxProCode"
               placeholder="请输入工序产品编号"
               clearable
               @keyup.enter.native="handleQuery"
             />
           </el-form-item>
           <el-form-item label="产品名称" prop="proName">
             <el-input
               v-model="queryParams.proName"
               placeholder="请输入产品名称"
               clearable
               @keyup.enter.native="handleQuery"
             />
           </el-form-item>
         -->
      <!-- <el-form-item label="是否接单0-未接 1-接单" prop="isJd">
         <el-input
           v-model="queryParams.isJd"
           placeholder="请输入是否接单0-未接 1-接单"
           clearable
           @keyup.enter.native="handleQuery"
         />
       </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
     <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['procontrol:orderInfo:add']"
        >新增</el-button>
      </el-col>-->
    <!--  <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['procontrol:orderInfo:edit']"
        >修改</el-button>
      </el-col>-->
      <!--<el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['procontrol:orderInfo:remove']"
        >删除</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-document-checked"
          size="mini"
          :disabled="multiple"
          @click="handleJdAll"
          v-hasPermi="['procontrol:control:jd']"
        >接单</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['procontrol:orderInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderInfoList" @selection-change="handleSelectionChange" :row-class-name="tableRowClassName">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="公司代码" align="center" prop="factoryCode" />
      <el-table-column label="公司名称" align="center" prop="factoryName" />
      <el-table-column label="派工单号" width="130" show-overflow-tooltip align="center" prop="danhao" />
      <el-table-column label="排产编号" width="160" show-overflow-tooltip align="center" prop="pcCode" />
      <el-table-column label="排产日期" align="center" prop="pcDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.pcDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单号" width="160" show-overflow-tooltip align="center" prop="orderNo" />
      <el-table-column label="员工工号"  width="130" align="center" prop="empNum" />
      <el-table-column label="员工姓名" width="100" align="center" prop="empName" />
      <el-table-column label="排产数量" align="center" prop="pcNum" />
      <el-table-column label="派工数量"  align="center" prop="pgNum" />
      <el-table-column label="报工数量" align="center" prop="bgNum" />
      <el-table-column label="返修数量" align="center" prop="returnNum" />
      <el-table-column label="生产线代码" width="130" align="center" prop="lineCode" />
      <el-table-column label="生产线名称" width="130" show-overflow-tooltip align="center" prop="lineName" />
      <el-table-column label="工位代码" width="130" show-overflow-tooltip align="center" prop="gwCode" />
      <el-table-column label="工位名称" width="130" show-overflow-tooltip align="center" prop="gwName" />
      <el-table-column label="产品类型" align="center" prop="proType" />
      <el-table-column label="工序产品编号" width="130" show-overflow-tooltip align="center" prop="gxProCode" />
      <el-table-column label="产品名称" width="130" show-overflow-tooltip align="center" prop="proName" />
      <el-table-column label="领料物料" width="200" show-overflow-tooltip   align="center" prop="dyYclCode" />
      <el-table-column label="报工物料"  width="200" show-overflow-tooltip align="center" prop="dyProCode" />
      <el-table-column label="物料识别码" width="280" show-overflow-tooltip   align="center" prop="itemIdentifyCode" />
      <el-table-column label="外径公差" width="120" align="center" prop="wjgc" />
      <el-table-column label="内径公差" width="120" align="center" prop="njgc" />
      <el-table-column label="厚度公差" width="120" align="center" prop="hdgc" />
      <el-table-column label="台径*台高" width="120" align="center" prop="tjtg" />
      <el-table-column label="中心距" width="120" align="center" prop="zxj" />
      <el-table-column label="孔径+孔数" width="120" align="center" prop="kjks" />
      <el-table-column label="计算重量" width="120" align="center" prop="jszl" />
      <el-table-column label="下料重量" width="120" align="center" prop="xlzl" />
      <el-table-column label="倒角" align="center" prop="dj" width="120"/>
      <el-table-column label="水线" align="center" prop="sx" width="120"/>
      <el-table-column label="密封面倒角" align="center" prop="mfmdj" width="120"/>
      <el-table-column label="说明" align="center" prop="content"  width="180" show-overflow-tooltip/>
      <el-table-column label="合同号" width="160" show-overflow-tooltip align="center" prop="contractNo" />
      <el-table-column label="生产日期" align="center" prop="scDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.scDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="交货日期" align="center" prop="jhDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.jhDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" width="160" align="center" prop="createTime" />
      <el-table-column label="创建者" align="center" prop="createBy" />
      <el-table-column label="更新时间" width="160" align="center" prop="updateTime" />
      <el-table-column label="更新者" align="center" prop="updateBy" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" fixed="right" width="130" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document-checked"
            @click="handleJd(scope.row)"
            v-if="scope.row.isJd != '1'"
            v-hasPermi="['procontrol:orderInfo:jd']"
          >接单</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document-delete"
            @click="handleDelete(scope.row)"
            v-if="scope.row.isJd != '1'"
            v-hasPermi="['procontrol:orderInfo:remove']"
          >撤单</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document-add"
            @click="handleBg(scope.row)"
            v-if="scope.row.isJd != '0' && scope.row.pgNum!=scope.row.bgNum "
            v-hasPermi="['procontrol:orderInfo:bg']"
          >报工</el-button>
         <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['procontrol:orderInfo:remove']"
          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改工单明细对话框 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="1100px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="单号" prop="danhao">
          <el-input v-model="form.danhao" placeholder="请输入单号" />
        </el-form-item>

        <el-form-item label="订单号" prop="orderNo">
          <el-input v-model="form.orderNo" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="合同号" prop="contractNo">
          <el-input v-model="form.contractNo" placeholder="请输入合同号" />
        </el-form-item>
        <el-form-item label="排产编号" prop="pcCode">
          <el-input v-model="form.pcCode" placeholder="请输入排产编号" />
        </el-form-item>
        <el-form-item label="排产日期" prop="pcDate">
          <el-date-picker clearable
                          v-model="form.pcDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择排产日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="排产数量" prop="pcNum">
          <el-input v-model="form.pcNum" placeholder="请输入排产数量" />
        </el-form-item>
        <el-form-item label="派工数量" prop="pgNum">
          <el-input v-model="form.pgNum" placeholder="请输入派工数量" />
        </el-form-item>
        <el-form-item label="报工数量" prop="bgNum">
          <el-input v-model="form.bgNum" placeholder="请输入报工数量" />
        </el-form-item>
        <el-form-item label="返修数量" prop="returnNum">
          <el-input v-model="form.returnNum" placeholder="请输入返修数量" />
        </el-form-item>
        <el-form-item label="生产线代码" prop="lineCode">
          <el-input v-model="form.lineCode" placeholder="请输入生产线代码" />
        </el-form-item>
        <el-form-item label="生产线名称" prop="lineName">
          <el-input v-model="form.lineName" placeholder="请输入生产线名称" />
        </el-form-item>
        <el-form-item label="工位代码" prop="gwCode">
          <el-input v-model="form.gwCode" placeholder="请输入工位代码" />
        </el-form-item>
        <el-form-item label="工位名称" prop="gwName">
          <el-input v-model="form.gwName" placeholder="请输入工位名称" />
        </el-form-item>
        <el-form-item label="员工工号" prop="empNum">
          <el-input v-model="form.empNum" placeholder="请输入员工工号" />
        </el-form-item>
        <el-form-item label="员工姓名" prop="empName">
          <el-input v-model="form.empName" placeholder="请输入员工姓名" />
        </el-form-item>
        <el-form-item label="工序产品编号" prop="gxProCode">
          <el-input v-model="form.gxProCode" placeholder="请输入工序产品编号" />
        </el-form-item>
        <el-form-item label="产品名称" prop="proName">
          <el-input v-model="form.proName" placeholder="请输入产品名称" />
        </el-form-item>
        <el-form-item label="领料物料" prop="dyYclCode">
          <el-input v-model="form.dyYclCode" placeholder="请输入领料物料" />
        </el-form-item>
        <el-form-item label="报工物料" prop="dyProCode">
          <el-input v-model="form.dyProCode" placeholder="请输入报工物料" />
        </el-form-item>
        <el-form-item label="生产日期" prop="scDate">
          <el-date-picker clearable
                          v-model="form.scDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择生产日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="交货日期" prop="jhDate">
          <el-date-picker clearable
                          v-model="form.jhDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择交货日期">
          </el-date-picker>
        </el-form-item>
      <!--  <el-form-item label="是否接单0-未接 1-接单" prop="isJd">
          <el-input v-model="form.isJd" placeholder="请输入是否接单0-未接 1-接单" />
        </el-form-item>-->
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :close-on-click-modal="false" :title="jd.title" :visible.sync="jd.open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="派工单号" prop="danhao">
              <el-input readonly v-model="form.danhao" placeholder="派工单号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工位名称" prop="gwName">
              <el-input readonly  v-model="form.gwName" placeholder="工位名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="员工工号" prop="empNum">
              <el-input readonly v-model="form.empNum" placeholder="员工工号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="员工姓名" prop="empName">
              <el-input readonly v-model="form.empName" placeholder="员工姓名" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="物料识别码" prop="itemIdentifyCode">
              <el-input readonly v-model="form.itemIdentifyCode" placeholder="物料识别码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="产品名称" prop="proName">
              <el-input readonly v-model="form.proName" placeholder="请输入产品名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="外径公差" prop="wjgc">
              <el-input readonly v-model="form.wjgc" placeholder="外径公差" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="内径公差" prop="njgc">
              <el-input readonly v-model="form.njgc" placeholder="内径公差" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="厚度公差" prop="hdgc">
              <el-input readonly v-model="form.hdgc" placeholder="厚度公差" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="台径*台高" prop="tjtg">
              <el-input readonly v-model="form.tjtg" placeholder="台径*台高" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="中心距" prop="zxj">
              <el-input readonly v-model="form.zxj" placeholder="中心距" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="孔径+孔数" prop="kjks">
              <el-input readonly v-model="form.kjks" placeholder="孔径+孔数" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="计算重量" prop="jszl">
              <el-input readonly v-model="form.jszl" placeholder="计算重量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="下料重量" prop="xlzl">
              <el-input readonly v-model="form.xlzl" placeholder="下料重量" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="倒角" prop="dj">
              <el-input readonly   v-model="form.dj" placeholder="倒角" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="水线" prop="sx">
              <el-input readonly  v-model="form.sx" placeholder="水线" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="密封面倒角" prop="mfmdj">
              <el-input readonly  v-model="form.mfmdj" placeholder="密封面倒角" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="说明" prop="content">
              <el-input readonly  v-model="form.content" placeholder="说明" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
          <el-form-item label="备注" prop="remark">
          <el-input readonly v-model="form.remark" type="textarea" placeholder="备注" />
        </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitJdForm">接 单</el-button>
        <el-button @click="jd.open = false">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :close-on-click-modal="false" :title="bg.title" :visible.sync="bg.open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
        <el-col :span="8">
            <el-form-item label="派工单号" prop="danhao">
              <el-input readonly v-model="form.danhao" placeholder="派工单号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="员工工号" prop="empNum">
              <el-input readonly v-model="form.empNum" placeholder="员工工号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="员工姓名" prop="empName">
              <el-input readonly v-model="form.empName" placeholder="员工姓名" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="物料识别码" prop="itemIdentifyCode">
              <el-input readonly v-model="form.itemIdentifyCode" placeholder="物料识别码" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="产品名称" prop="proName">
              <el-input readonly v-model="form.proName" placeholder="请输入产品名称" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="工位名称" prop="gwName">
              <el-input readonly  v-model="form.gwName" placeholder="工位名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="外径公差" prop="wjgc">
              <el-input readonly v-model="form.wjgc" placeholder="外径公差" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="内径公差" prop="njgc">
              <el-input readonly v-model="form.njgc" placeholder="内径公差" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="厚度公差" prop="hdgc">
              <el-input readonly v-model="form.hdgc" placeholder="厚度公差" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="台径*台高" prop="tjtg">
              <el-input readonly v-model="form.tjtg" placeholder="台径*台高" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="中心距" prop="zxj">
              <el-input readonly v-model="form.zxj" placeholder="中心距" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="孔径+孔数" prop="kjks">
              <el-input readonly v-model="form.kjks" placeholder="孔径+孔数" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="计算重量" prop="jszl">
              <el-input readonly v-model="form.jszl" placeholder="计算重量" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="下料重量" prop="xlzl">
              <el-input readonly v-model="form.xlzl" placeholder="下料重量" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="倒角" prop="dj">
                <el-input readonly  v-model="form.dj" placeholder="倒角" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="水线" prop="sx">
                <el-input readonly  v-model="form.sx" placeholder="水线" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="密封面倒角" prop="mfmdj">
                <el-input  readonly v-model="form.mfmdj" placeholder="密封面倒角" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="说明" prop="content">
                <el-input readonly  v-model="form.content" placeholder="说明" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-col :span="8">
            <el-form-item label="派工数量" prop="pgNum">
              <el-input readonly v-model="form.pgNum" placeholder="派工数量" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="已报工数量" prop="ybgNum">
              <el-input readonly v-model="form.ybgNum" placeholder="已报工数量" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-card shadow="always">
        <el-row>
          <el-col :span="8">
            <el-form-item label="领料物料" prop="dyYclCode">
              <el-select  v-model="form.dyYclCode" placeholder="请选择报工物料">
                <el-option
                  v-for="item in dyYclCodeOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                  <span style="float: left">{{ item.label }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{ item.value }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8" >
          <el-form-item label="报工物料" prop="dyProCode">
            <el-select  v-model="form.dyProCode" placeholder="请选择报工物料">
              <el-option
                v-for="item in dyProCodeOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                <span style="float: left">{{ item.label }}</span>
                <span style="float: right; color: #8492a6; font-size: 13px">{{ item.value }}</span>
              </el-option>
            </el-select>
          </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="报工数量" prop="bgNum">
              <el-input v-model="form.bgNum" placeholder="请输入报工数量" />
            </el-form-item>
          </el-col>
        </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="备注" prop="remark">
                <el-input  v-model="form.remark" type="textarea" placeholder="备注" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitBgForm">报 工</el-button>
        <el-button @click="bg.open = false">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import { listOrderInfo, getOrderInfo, delOrderInfo, addOrderInfo, updateOrderInfo,getBgOrderInfo,addJdOrderInfo,addBgOrderInfo,addJdAllOrderInfo,getBgOrderinfoItem} from "@/api/procontrol/orderInfo";

  export default {
    name: "OrderInfoPg",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 工单明细表格数据
        orderInfoList: [],
        //领料物料
        dyYclCodeOptions: [],
        //报工物料
        dyProCodeOptions: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        jd:{
          // 弹出层标题
          title: "",
          // 是否显示弹出层
          open: false,
        },
        bg:{
          // 弹出层标题
          title: "",
          // 是否显示弹出层
          open: false,
        },
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          factoryCode: null,
          danhao: null,
          orderNo: null,
          contractNo: null,
          pcCode: null,
          pcDate: null,
          scDate: null,
          jhDate: null,
          lineCode: null,
          lineName: null,
          gwCode: null,
          gwName: null,
          empNum: null,
          empName: null,
          proType: null,
          gxProCode: null,
          proName: null,
          dyProCode: null,
          dyYclCode: null,
          isJd: null,
          itemIdentifyCode: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          bgNum: [
            { required: true, message: "报工数量不能为空", trigger: "blur" }
          ],
          dyYclCode: [
            { required: true, message: "请输入领料物料", trigger: "blur" }
          ],
          dyProCode: [
            { required: true, message: "请选择报工物料", trigger: "blur" }
          ],
         /* returnNum: [
            { required: true, message: "返修数量不能为空", trigger: "blur" }
          ],*/
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询工单明细列表 */
      getList() {
        this.loading = true;
        listOrderInfo(this.queryParams).then(response => {
          this.orderInfoList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      tableRowClassName({row, rowIndex}) {
        if (row.isJd=='0') {
          return 'warning-row';
        } else if(row.isJd=='1' && row.bgNum<row.pgNum){
          return 'warning2-row';
        }else {
          return ' ';
        }
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          factoryCode: null,
          factoryName: null,
          danhao: null,
          orderNo: null,
          contractNo: null,
          pcCode: null,
          pcDate: null,
          scDate: null,
          jhDate: null,
          lineCode: null,
          lineName: null,
          gwCode: null,
          gwName: null,
          empNum: null,
          empName: null,
          proType: null,
          gxProCode: null,
          proName: null,
          dyProCode: null,
          dyYclCode: null,
          pcNum: null,
          pgNum: null,
          bgNum: null,
          returnNum: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          isJd: null,
          remark: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加工单明细";
      },
      handleJdAll() {
        const id =  this.ids
        this.$modal.confirm('是否确认勾选的全部接单吗？').then(function() {
          return addJdAllOrderInfo(id);
        }).then(() => {
          this.getList();
          this.$modal.alertSuccess("接单成功");
        }).catch(() => {});
      },
      /*接单按钮操作*/
      handleJd(row) {
        this.reset();
        const id = row.id
        getOrderInfo(id).then(response => {
          this.form = response.data;
          this.jd.open = true;
          this.form.isJd ="1";
          this.jd.title = "接单";
        });
      },
      /*接单按钮操作*/
      handleBg(row) {
        this.reset();
        const id = row.id || this.ids
        getBgOrderInfo(id).then(response => {
          getBgOrderinfoItem(id).then(response1 => {
            this.form = response.data;
            this.bg.open = true;
            this.bg.title = "报工";
            this.dyYclCodeOptions=response1.data.llwlData;
            this.dyProCodeOptions=response1.data.bgwlData;
          });
        });
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getOrderInfo(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改工单明细";
        });
      },

      submitBgForm() {
        if (this.form.id != null) {
         let bgNum= Number(this.form.bgNum);
         let pgNum= Number(this.form.pgNum);
         let rNum= Number(this.form.returnNum);
         let ybgNum= Number(this.form.ybgNum);
         if(bgNum<=0){
           this.$modal.alertSuccess("报工数量必须满足大于0");
            return;
         }
          if(pgNum<bgNum+ybgNum){
            this.$modal.alertSuccess("报工数量超出派工数量");
            return;
          }
          this.$refs["form"].validate(valid => {
            if (valid) {
              addBgOrderInfo(this.form).then(response => {
                this.$modal.alertSuccess("报工完成");
                this.bg.open = false;
                this.getList();
              });
            }
          });
        }
      },
      submitJdForm() {
        if (this.form.id != null) {
          addJdOrderInfo(this.form).then(response => {
            this.$modal.alertSuccess("接单成功");
            this.jd.open = false;
            this.getList();
          });
        }
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateOrderInfo(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addOrderInfo(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认撤销派工单吗？').then(function() {
          return delOrderInfo(ids);
        }).then(() => {
          this.getList();
          this.$modal.alertSuccess("撤销成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('procontrol/orderInfo/export', {
          ...this.queryParams
        }, `orderInfo_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
<style lang="scss" scoped>
  ::v-deep .el-table .warning-row {
    background: #ffe4e1;
  }
  ::v-deep .el-table .warning2-row {
    background: #fcffc3;
  }
</style>
